﻿using System.Web;
using System.Web.Services;
using Ext.Net;
using FSS.BLL.Services;
using FSS.BLL.Entities;
using System.Collections.Generic;
using FSS.Core.Util;

namespace SalesManagement.Modules.List
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SearProduct : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string Type = "product";
            var start = 0;
            var limit = 100;
            var sort = string.Empty;
            var dir = string.Empty;
            var query = string.Empty;

            if (!string.IsNullOrEmpty(context.Request["start"]))            
                start = int.Parse(context.Request["start"]);
          

            if (!string.IsNullOrEmpty(context.Request["limit"]))           
                limit = int.Parse(context.Request["limit"]);
            if (!string.IsNullOrEmpty(context.Request["sort"]))         
                sort = context.Request["sort"];   
            if (!string.IsNullOrEmpty(context.Request["dir"]))          
                dir = context.Request["dir"];
            if (!string.IsNullOrEmpty(context.Request["query"]))          
                query = context.Request["query"];
            if (!string.IsNullOrEmpty(context.Request["type"]))
                Type = context.Request["type"];
            //if (Type == "product")
            //{
                ProductService Service = ProductService.GetInstance();
                int Total = 0;
                List<ProductEntity> resul = (List<ProductEntity>)Service.SearchProduct(query, start, limit, out Total);
                context.Response.Write(string.Format("{{total:{1},'SearProduct':{0}}}", JSON.Serialize(resul), Total));
            //}
            //else if (Type == "VoucherIn")
            //{
            //    VoucherService Service = VoucherService.GetInstance();
            //    VoucherEntity Parramter = new VoucherEntity();
            //    Parramter.VoucherNo = query;
            //    int? ProviderID = null;
            //    if (context.Request["pro"] != null)
            //        ProviderID = Format.ConvertToInt(context.Request["pro"]);
            //    if (ProviderID > 0)
            //        Parramter.ObjectId= ProviderID;
            //    List<VoucherEntity> resul = (List<VoucherEntity>)Service.SearData(Parramter);
            //    context.Response.Write(string.Format("{{total:{1},'SearProduct':{0}}}", JSON.Serialize(resul), resul.Count));
            //}
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
